package com.example.mybatisplus.web.controller;

import com.example.mybatisplus.model.dto.DeleteDTO;
import com.example.mybatisplus.model.dto.PageDTO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.LearnService;
import com.example.mybatisplus.model.domain.Learn;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2023-01-07
 * @version v1.0
 */
@Controller
@RequestMapping("/api/learn")
public class LearnController {

    private final Logger logger = LoggerFactory.getLogger( LearnController.class );

    @Autowired
    private LearnService learnService;

    @PostMapping("save")
    @ResponseBody
    public JsonResponse save(@RequestBody Learn learn){
        learnService.rep(learn);
        learnService.insert(learn);
        return JsonResponse.success(true);
    }


    @GetMapping("list")
    @ResponseBody
    public JsonResponse list(Learn learn, PageDTO pageDTO){
        return JsonResponse.success(learnService.listPage(learn,pageDTO));
    }

    @PostMapping("removeByIds")
    @ResponseBody
    public JsonResponse removeByIds(@RequestBody DeleteDTO deleteDTO){
        boolean b = learnService.removeByIds(deleteDTO.getIds());
        return JsonResponse.success(b);
    }
}

